package cn.tedu.tmall.front.mall.dao.persist.repository.impl;

import cn.tedu.tmall.common.pojo.vo.PageData;
import cn.tedu.tmall.common.util.PageInfoToPageDataConverter;
import cn.tedu.tmall.front.mall.dao.persist.mapper.OrderMapper;
import cn.tedu.tmall.front.mall.dao.persist.repository.IOrderRepository;
import cn.tedu.tmall.front.mall.pojo.entity.Order;
import cn.tedu.tmall.front.mall.pojo.vo.OrderListItemVO;
import cn.tedu.tmall.front.mall.pojo.vo.OrderStandardVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class OrderRepository implements IOrderRepository {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public int insert(Order order) {
        return orderMapper.insert(order);
    }

    @Override
    public OrderStandardVO getStandardByIdAndUser(Long orderId, Long userId) {
        log.debug("开始处理根据订单id查询用户的订单");
        return orderMapper.getStandardByIdAndUser(orderId,userId);
    }

    @Override
    public PageData<OrderListItemVO> listByUser(Long userId, Integer pageNum, Integer pageSize) {
        log.debug("开始根据用户的id查询订单列表");
        PageHelper.startPage(pageNum,pageSize);
        List<OrderListItemVO> list = orderMapper.listByUser(userId);
        PageInfo<OrderListItemVO> pageInfo=new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

}
